import axios from 'axios'
import API from './contants'

// 获取员工列表
export function getEmployeeList(params) {
  return axios.get(API.EMPLOYEE_LIST, { params })
    .then(response => response.data)
    .catch(error => {
      console.error('Failed to get employee list:', error)
      throw error
    })
}

// 新增员工
export function addEmployee(data) {
  return axios.post(API.EMPLOYEE_ADD, data)
    .then(response => response.data)
    .catch(error => {
      console.error('Failed to add employee:', error)
      throw error
    })
}

// 删除员工
export function deleteEmployee(id) {
  return axios.delete(`${API.EMPLOYEE_DELETE}/${id}`)
    .then(response => response.data)
    .catch(error => {
      console.error('Failed to delete employee:', error)
      throw error
    })
}

// 批量删除员工
export function deleteEmployees(ids) {
  return axios.delete(API.EMPLOYEE_DELETE_BATCH, { params: { ids }})
    .then(response => response.data)
    .catch(error => {
      console.error('Failed to delete employees:', error)
      throw error
    })
}

// 更新员工
export function updateEmployee(id, data) {
  const url = API.EMPLOYEE_UPDATE.replace('{id}', id);
  return axios.put(url, data)
    .then(response => response.data)
    .catch(error => {
      console.error('Failed to update employee:', error)
      throw error
    })
}




export default {
  getEmployeeList,
  addEmployee,
  deleteEmployee,
  deleteEmployees,
  updateEmployee
}
